package com.servlet;

import com.daofactory.DaoFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 徐洲
 * @version 1.0
 */
public class CommentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String action = request.getParameter("action");
        HttpSession session = request.getSession();
        if ("getAllById".equals(action)){
            String userid = request.getParameter("userid");
            String article_id = request.getParameter("article_id");
            String content = request.getParameter("content");
            if (DaoFactory.getCommentDAOInstance().addComment(article_id, userid, content)){
                session.setAttribute("info", "发布评论成功");
            } else {
                session.setAttribute("info", "发布评论失败");
            }
        }
        response.sendRedirect("./infoPage.jsp");
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
